package apis

import (
	"gitee.com/byx_darwin/ncloud-go/core"
	"gitee.com/byx_darwin/ncloud-go/core/net/consts"
	"strconv"
)

type QueryLineConditions struct {
	Total    int64  `json:"total"`
	Code     string `json:"code"`
	City     string `json:"city"`
	Duration int64  `json:"duration"`
}
type LineGetRequest struct {
	core.NCloudRequest
	QueryLineConditions
}

func NewQueryLineGetRequestWithParams(total, duration int64,
	code, city string) *LineGetRequest {
	return &LineGetRequest{
		NCloudRequest: core.NCloudRequest{
			Path:   "/line",
			Method: consts.MethodGet,
		},
		QueryLineConditions: QueryLineConditions{
			Total:    total,
			Code:     code,
			City:     city,
			Duration: duration,
		},
	}
}

func (l *LineGetRequest) SetTotal(total int64) {
	l.Total = total
}
func (l *LineGetRequest) SetCode(code string) {
	l.Code = code
}
func (l *LineGetRequest) SetCity(city string) {
	l.City = city
}
func (l *LineGetRequest) SetDuration(duration int64) {
	l.Duration = duration
}

func (l *LineGetRequest) GetPath() string {
	path := l.Path
	path += "?total=" + strconv.Itoa(int(l.Total))
	if l.Duration > 0 {
		path += "&duration=" + strconv.Itoa(int(l.Duration))
	}
	if l.Code != "" {
		path += "&code=" + l.Code
	}
	if l.City != "" {
		path += "&city=" + l.City
	}
	return path
}

type LineInfo struct {
	Account  string `json:"account"`
	Password string `json:"password"`
	Proxy    string `json:"proxy"`
}

type QueryLineGetResponse struct {
	Code    int        `json:"code"`
	Msg     string     `json:"msg"`
	Data    []LineInfo `json:"data"`
	TrackID string     `json:"track_id"`
}
